//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;

namespace STT.Business
{
    public class BTbHeSoLuong
    {
        public static DataTable Search(ETbHeSoLuong hsl)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"HeSL", hsl.HeSL);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHeSoLuong_Search", pr);
            return all;
        }

        public static bool KiemTraDuLieu(ETbHeSoLuong hsl)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"HeSL", hsl.HeSL);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHeSoLuong_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        //-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHeSoLuong_SelectAll", null);
            return all;
        }
        public static DataTable LoadDropdownlist(int MaNhomNL)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaNhomNL", MaNhomNL);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHeSoLuong_LoadDropdownlist", pr);
            return all;
        }
        //-----------------------------------------------------------//
        public static void Insert(ETbHeSoLuong OTbHeSoLuong)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"HeSL", OTbHeSoLuong.HeSL);
            pr[1] = new SqlParameter(@"MoTa", OTbHeSoLuong.MoTa);
            pr[2] = new SqlParameter(@"MaNhomNL", OTbHeSoLuong.MaNhomNL);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbHeSoLuong_Insert", pr);
        }
        //-----------------------------------------------------------//
        public static void Update(ETbHeSoLuong OTbHeSoLuong)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"HeSL", OTbHeSoLuong.HeSL);
            pr[1] = new SqlParameter(@"MoTa", OTbHeSoLuong.MoTa);
            pr[2] = new SqlParameter(@"MaNhomNL", OTbHeSoLuong.MaNhomNL);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbHeSoLuong_Update", pr);
        }
        //-----------------------------------------------------------//
        public static void Delete(double HeSL)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"HeSL", HeSL);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbHeSoLuong_Delete", pr);
        }
        //-----------------------------------------------------------//
        public static ETbHeSoLuong SelectByID(double HeSL)
        {
            ETbHeSoLuong OTbHeSoLuong = new ETbHeSoLuong();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"HeSL", HeSL);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbHeSoLuong_SelectByID", pr);
            if (idr.Read())
                OTbHeSoLuong = GetOneTbHeSoLuong(idr);
            idr.Close();
            idr.Dispose();
            return OTbHeSoLuong;
        }
        //-----------------------------------------------------------//
        private static ETbHeSoLuong GetOneTbHeSoLuong(IDataReader idr)
        {
            ETbHeSoLuong OTbHeSoLuong = new ETbHeSoLuong();
            if (idr["HeSL"] != DBNull.Value)
                OTbHeSoLuong.HeSL = (double)idr["HeSL"];
            if (idr["MoTa"] != DBNull.Value)
                OTbHeSoLuong.MoTa = (string)idr["MoTa"];
            return OTbHeSoLuong;
        }
        //-----------------------------------------------------------//
        public static bool TestByID(double HeSL)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"HeSL", HeSL);
            pr[1] = new SqlParameter(@"TestID", SqlDbType.Bit);
            pr[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbHeSoLuong_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
        //-----------------------------------------------------------//
        public static List<ETbHeSoLuong> ListAll()
        {
            List<ETbHeSoLuong> list = new List<ETbHeSoLuong>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbHeSoLuong_SelectAll", null);
            while (idr.Read())
                list.Add(GetOneTbHeSoLuong(idr));
            if (idr.IsClosed == false)
            {
                idr.Close();
                idr.Dispose();
            }
            return list;
        }
    }

}
